package univer.oko;

import java.io.File;
import java.io.PrintWriter;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;


/**
 * @author Eduard Dudar
 *         Date: 14.01.2006
 */
public class CDThreadGroup extends ThreadGroup {
    protected PrintWriter pw;
    protected SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");


    public CDThreadGroup(String name, String pattern) {
        super(name);
        try {
            File dir = new File(pattern);
            dir.mkdirs();
            FileHandler handler = new FileHandler(pattern + "/log", 10 * 1024 * 1024 /*10M*/, 50, true);
            handler.setFormatter(new SimpleFormatter()/*new XMLFormatter()*/);

            Logger.global.addHandler(handler);
            Logger.global.setLevel(Level.ALL);
        }
        catch (Exception e) {
            throw new RuntimeException(e);
        }
    }

    public void uncaughtException(Thread t, Throwable e) {
        Logger.global.log(Level.SEVERE, "[" + sdf.format(new Date(System.currentTimeMillis())) + "]: Uncaught Exception in " + t, e);
    }
}
